using System;
using System.Collections.Generic;
using System.Text;
using Wrath.Xml;
using Wrath.RuleForge.Interfaces;
using System.ComponentModel;

namespace Wrath.RuleForge.Property
{
    public class DieBoxWrapper : IPropertyWrapper<Element>
    {
        private bool hasChanged;
        private Element element;

        // TODO: Frame selection & Icon selection & Font Selection Dropdown

        private Wrath.Xml.Attribute frameName;
        private Wrath.Xml.Attribute secretIcon;
        private Wrath.Xml.Attribute marginValue;
        private Wrath.Xml.Attribute marginNumberTail;
        private Wrath.Xml.Attribute dieCountMargin;
        private Wrath.Xml.Attribute dieCountFont;

        [Category("Die Box")]
        [Description("The name of the frame to use for the die box.")]
        [DisplayName("Frame Name")]
        public string FrameName { get { if (frameName != null) return frameName.Value; return ""; } set { if (frameName != null) frameName.Value = value; } }

        [Category("Die Box")]
        [Description("")]
        [DisplayName("Secret Icon")]
        public string SecretIcon { get { if (secretIcon != null) return secretIcon.Value; return ""; } set { if (secretIcon != null) secretIcon.Value = value; } }

        [Category("Margins")]
        [Description("")]
        [DisplayName("Margin")]
        public string MarginValue { get { if (marginValue != null) return marginValue.Value; return ""; } set { if (marginValue != null) marginValue.Value = value; } }

        [Category("Margins")]
        [Description("")]
        [DisplayName("Number Tail")]
        public string MarginNumberTail { get { if (marginNumberTail != null) return marginNumberTail.Value; return ""; } set { if (marginNumberTail != null) marginNumberTail.Value = value; } }

        [Category("Die Count Tracker")]
        [Description("")]
        [DisplayName("Margin")]
        public string DieCountMargin { get { if (dieCountMargin != null) return dieCountMargin.Value; return ""; } set { if (dieCountMargin != null) dieCountMargin.Value = value; } }

        [Category("Die Count Tracker")]
        [Description("")]
        [DisplayName("Font")]
        public string DieCountFont { get { if (dieCountFont != null) return dieCountFont.Value; return ""; } set { if (dieCountFont != null) dieCountFont.Value = value; } }

        public DieBoxWrapper(Element element)
        {
            hasChanged = false;
            this.element = element;

            Element tempElement = element.FindFirstElement("frame", false);
            frameName = tempElement.FindAttribute("name");

            tempElement = element.FindFirstElement("secreticon", false);
            secretIcon = tempElement.FindAttribute("name");

            tempElement = element.FindFirstElement("margin", false);
            marginValue = tempElement.FindAttribute("value");
            marginNumberTail = tempElement.FindAttribute("numbertailmargin");

            tempElement = element.FindFirstElement("tracker", false);
            dieCountMargin = tempElement.FindAttribute("diecountmargin");
            dieCountFont = tempElement.FindAttribute("diecountfont");
        }

        #region IPropertyWrapper<Element> Members

        [Browsable(false)]
        public bool HasChanged
        {
            get
            {
                return hasChanged;
            }
            set
            {
                hasChanged = value;
            }
        }

        [Browsable(false)]
        public Element Data
        {
            get { return element; }
        }

        #endregion
    }
}
